home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Library / OutlineBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  6.0 KB  |  230 lines

  1.  
  2. #include "parms.h" /* added for proper prototyping -- EDB */
  3. /* Additions for prototypes -- EDB */
  4. #include "GraphicObject.h"
  5.  
  6. #include "GraphicObjectClass.h"
  7. #include "OutlineBox.h"
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "minmax.h"
  11. #include <graphics/gfxmacros.h>
  12. #ifndef __GNUC__
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <clib/diskfont_protos.h>
  17. #endif
  18. #ifdef __GNUC__
  19. #include <proto/exec.h>
  20. #include <proto/intuition.h>
  21. #include <proto/graphics.h>
  22. #include <proto/diskfont.h>
  23. #endif
  24. #ifdef __SASC
  25. #include <proto/exec.h>
  26. #include <proto/intuition.h>
  27. #include <proto/graphics.h>
  28. #include <proto/diskfont.h>
  29. #endif
  30.  
  31. #include "amigamem.h"
  32.  
  33. Point OutlineBox_Location( OutlineBox *self )
  34. {
  35.    return self->Location;
  36. }
  37.  
  38.  
  39. Point OutlineBox_SetLocation( OutlineBox *self,
  40.                              PIXELS    LeftEdge,
  41.                              PIXELS    TopEdge )
  42. {
  43.    self->Location.x = LeftEdge;
  44.    self->Location.y = TopEdge;
  45.    return self->Location;
  46. }
  47.  
  48. Point OutlineBox_Size( OutlineBox *self )
  49. {
  50.    return self->Size;
  51. }
  52.  
  53. Point OutlineBox_AskSize( OutlineBox      *self,
  54.                          PIXELS         Width,
  55.                          PIXELS         Height )
  56. {
  57.    Point size;
  58.  
  59.    size.x = MAX( Width, 6 );
  60.    size.y = MAX( Height, 6 );
  61.    return size;
  62. }
  63.  
  64.  
  65. Point OutlineBox_SetSize( OutlineBox *self,
  66.                          PIXELS    Width,
  67.                          PIXELS    Height )
  68. {
  69.    Point size;
  70.  
  71.    size = AskSize( (GraphicObject *)self, Width, Height );
  72.    self->Size.x = size.x;
  73.    self->Size.y = size.y;
  74.  
  75.    pcg_Init3DThinBevel( &self->Bevel, 0, 0, size.x, size.y, 0,
  76.       self->Pens.DarkPen, self->Pens.BrightPen, NULL );
  77.  
  78.    return size;
  79. }
  80.  
  81.  
  82. #define FONT_WIDTH  8
  83. #define FONT_HEIGHT 8
  84. #define BASELINE    7
  85.  
  86. void OutlineBox_Render( OutlineBox *self,
  87.                       RastPort *RPort )
  88. {
  89.    short width, length, x, y;
  90.    Point location;
  91.    Point size;
  92.  
  93.    /* Additions to correct font behavior under AmigaDOS 2.x/3.x -- EDB */
  94.    TextAttr pcg_Topaz80 =
  95.    { "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  96.  
  97.    struct TextFont *myfont, *oldfont;
  98.  
  99.    location = Location( (GraphicObject *)self );
  100.    size     = Size( (GraphicObject *)self );
  101.    length   = strlen(self->Label);
  102.    width    = length * FONT_WIDTH;
  103.    x        = location.x + size.x/2 - width/2;
  104.    y        = location.y - FONT_HEIGHT/2 + BASELINE;
  105.  
  106.    DrawBorder( RPort, (struct Border*) &self->Bevel, location.x, location.y );
  107.  
  108.    SetDrMd( RPort, JAM2 );
  109.    SetAPen( RPort, self->Pens.FrontPen );
  110.    SetBPen( RPort, self->Pens.BackPen );
  111.    Move( RPort, x, y );
  112.  
  113. /* Under 2.x/3.x Amiga OS we cannot presume the rastport default font is topaz */
  114. /* so we open it ourselves and close it when done -- EDB */
  115. if( myfont = OpenDiskFont( &pcg_Topaz80 ) )
  116.   {
  117.      oldfont = RPort->Font;
  118.      SetFont( RPort, myfont );
  119.    Text( RPort, self->Label, length );
  120.      SetFont( RPort, oldfont );
  121.      CloseFont( myfont );
  122.   }
  123. }
  124.  
  125. char *OutlineBox_Title( OutlineBox *self )
  126. {
  127.    return self->Label;
  128. }
  129.  
  130. BOOL OutlineBox_SetTitle( OutlineBox *self, char *title )
  131. {
  132.    Afree( self->Label );
  133.    self->Label = Astrdup(title);
  134.    return TRUE;
  135. }
  136.  
  137. #if 0 /* not ready for prime time */
  138. /* EDB -- Added Default Font Support Methods */
  139. extern TextAttr go_DefaultFont;
  140.  
  141. TextAttr *OutlineBox_DefaultFont( OutlineBox *self )
  142. {
  143.    if( self->LabelText.ITextFont != NULL )
  144.       return self->LabelText.ITextFont;
  145.    else return &go_DefaultFont;  /* Topaz80 */
  146. }
  147.  
  148. BOOL OutlineBox_SetDefaultFont( OutlineBox *self, TextAttr *default_font )
  149. {
  150.    struct TextFont *myfont;
  151.  
  152.    if( default_font != NULL )
  153.    {      /* check to see if font is really available */
  154.      if( myfont = OpenDiskFont( default_font ) )
  155.        {
  156.        self->LabelText.ITextFont = default_font;
  157.  
  158.        CloseFont( myfont );
  159.        /* Get ourselves back into alignment */
  160.        AlignText( &self->LabelText, Size( (GraphicObject *)self ) );
  161.        return TRUE;
  162.        }
  163.      else return FALSE; /* font is not available */
  164.    }
  165.    else return FALSE;   /* pointer was invalid */
  166. }
  167.  
  168. #endif /* not ready for prime time */
  169.  
  170. BOOL OutlineBox_elaborated = FALSE;
  171.  
  172. struct GraphicObjectClass OutlineBox_Class;
  173.  
  174.  
  175. void OutlineBoxClass_Init( struct GraphicObjectClass *class )
  176. {
  177.    GraphicObjectClass_Init( class );
  178.    class->isa         = GraphicObjectClass();
  179.    class->ClassName   = "OutlineBox";
  180.    class->CleanUp     = NULL;
  181.    class->Location    = (Point(*)(GraphicObject *))OutlineBox_Location;
  182.    class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))OutlineBox_SetLocation;
  183.    class->Size        = (Point(*)(GraphicObject *))OutlineBox_Size;
  184.    class->AskSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))OutlineBox_AskSize;
  185.    class->SetSize     = (Point(*)(GraphicObject *, PIXELS, PIXELS))OutlineBox_SetSize;
  186.    class->SizeFlags   = GraphicObject_SizeFlagsAll;
  187.    class->Render      = (void(*)(GraphicObject *, RastPort *))OutlineBox_Render;
  188.    class->SetTitle    = (BOOL(*)(GraphicObject *, char *))OutlineBox_SetTitle;
  189.    class->Title       = (char*(*)(GraphicObject *))OutlineBox_Title;
  190.  
  191. #if 0 /* not ready for primetime */
  192. /* EDB -- added default font methods */
  193.    class->DefaultFont = OutlineBox_DefaultFont;
  194.    class->SetDefaultFont = OutlineBox_SetDefaultFont;
  195. #endif
  196.  
  197.  
  198. }
  199.  
  200.  
  201. struct GraphicObjectClass *OutlineBoxClass( void )
  202. {
  203.    if( ! OutlineBox_elaborated )
  204.    {
  205.       OutlineBoxClass_Init( &OutlineBox_Class );
  206.       OutlineBox_elaborated = TRUE;
  207.    }
  208.  
  209.    return &OutlineBox_Class;
  210. }
  211.  
  212. void OutlineBox_Init(  OutlineBox    *self,
  213.                        PIXELS       LeftEdge,
  214.                        PIXELS       TopEdge,
  215.                        PIXELS       Width,
  216.                        PIXELS       Height,
  217.                        pcg_3DPens   Pens,
  218.                        char        *Label )
  219. {
  220.    GraphicObject_Init( (GraphicObject *)self );
  221.  
  222.    self->isa         = OutlineBoxClass();
  223.    self->PObjectName  = NULL;
  224.    self->Label       = NULL;
  225.    self->Pens        = Pens;
  226.    SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
  227.    SetSize( (GraphicObject *)self, Width, Height );
  228.    SetTitle( (GraphicObject *)self, Label );
  229. }
  230.